<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客正文</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/blog_content.css">
    <link rel="stylesheet" href="editor.md/css/editormd.preview.min.css" />
    <script src="js/jquery.min.js"></script>
    <script src="editor.md/editormd.js"></script>
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>
    <script src="js/commom.js"></script>

</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/博客系统logo.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="blog_list.html">主页</a>
        <a href="blog_add.html">写博客</a>
        <a href="javascript:logout()">退出</a>
    </div>
    <!-- 版心 -->
    <div class="container">
        <!-- 左侧个人信息 -->
        <div class="container-left">
            <div class="card">
                <img src="" class="avtar" alt="" id="photo">
                <h4 id="nickname"></h4><br>
                <a href="/upd_password.html" id="draft1">修改密码</a>
                <div class="counter">
                    <a href="myblog_list.html" id="draft2">文章</a>
                    <a href="/mydraft.html" id="draft3">草稿箱</a>
                </div>
                <div class="counter">
                    <span id="artCount"></span>
                    <span id="draftCount"></span>
                </div>
            </div>
        </div>
        <!-- 右侧内容详情 -->
        <div class="container-right">
            <div class="blog-content">
                <!-- 博客标题 -->
                <h3 id="title"> </h3>
                <!-- 博客时间 -->
                <div class="date">保存时间: <span id="updatetime"> </span> &nbsp;&nbsp;&nbsp;
                <!-- 博客正文 -->
                <div id="editorDiv">

                </div>
            </div>
        </div>

    </div>
    <script type="text/javascript">
            var editormd;
            function initEdit(md){

                editormd = editormd.markdownToHTML("editorDiv", {
                markdown : md, // Also, you can dynamic set Markdown text
                // htmlDecode : true,  // Enable / disable HTML tag encode.
                // htmlDecode : "style,script,iframe",  // Note: If enabled, you should filter some dangerous HTML tags for website security.
                });
            }

            // 获取文章详情信息
            function getArtDetail(id) {
                if (id == "") {
                    alert("非法参数!访问失败!")
                    return;
                }
                jQuery.ajax({
                    url: "/art/detail",
                    type: "POST",
                    data: {"id": id},
                    success: function(result) {
                        if (result != null && result.code == 200) {
                            // 查询成功.
                            jQuery("#title").html(result.data.art.title);
                            jQuery("#updatetime").html(result.data.art.updatetime);
                            initEdit(result.data.art.content);

                            // 得到用户 id, 查询用户的信息
                            showUser(result.data.art.uid);
                        } else {
                            alert("查询失败!请重试!")
                        }
                    }

                });
            }
            getArtDetail(getUrlValue("id"));

            // todo: 查询用户的信息
            function showUser(id) {
                  jQuery.ajax({
                    url: "/user/showuser",
                    type: "POST",
                    data: {"id": id},
                    success: function(result) {
                        if (result != null && result.code == 200 && result.data.id > 0) {
                            jQuery("#nickname").text(result.data.nickname);
                            jQuery("#artCount").text(result.data.artCount);
                            jQuery("#draftCount").text(result.data.draftCount);
                            // $("#photo").attr("src","http://localhost:8082" + result.data.photo);
                            $("#photo").attr("src","http://43.143.87.64:8082" + result.data.photo);
                        } else {
                            alert("页面加载失败, 请再次刷新!");
                        }
                    }
                  });
            }


            
    </script> 
</body>

</html>